package cn.hfgf.springmvc.controller;

import cn.hfgf.springmvc.dal.model.TUser;
import cn.hfgf.springmvc.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;

/**
 * @author wangxuekai
 * @version 2.0
 * @Date 2017/1/16.
 * @since 2.0
 */
@Controller
@RequestMapping("/user")
public class UserController {
    private static final Logger LOGGER = LoggerFactory.getLogger(UserController.class);

    @Resource(name = "userService")
    private UserService userService;

    @RequestMapping(value = "/register",method = RequestMethod.GET)
    public String register(){
        return "user/register";
    }

    @RequestMapping(value = "/doRegister",method = RequestMethod.POST)
    public String doRegister(TUser tUser, Model model){
        LOGGER.info("user={}",tUser);
        boolean bSuc = userService.insert(tUser);
        model.addAttribute("user",tUser);
        if (bSuc){
            LOGGER.info("注册成功!user={}",tUser);
            return "user/register_success";
        }else {
            LOGGER.error("注册失败!user={}",tUser);
            return "user/register_fail";
        }
    }

    @RequestMapping(value = "/login",method = RequestMethod.GET)
    public String login(){
        return "user/login";
    }

    @RequestMapping(value = "doLogin",method = RequestMethod.POST)
    public String doLogin(String userName,String pwd,Model model){
        //todo 实现登陆逻辑
        return "";
    }

}
